using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;

namespace TF.Access {
	public partial class TF_EventDetail {
		#region Fields
		private int id;
		private int eventHId;
		private int toCityId;
		private int preCityId;
		private DateTime startDate = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
		private DateTime endDate = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
		private int dayNumber;
		#endregion
		
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the TF_EventDetail class.
		/// </summary>
		public TF_EventDetail() {
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_EventDetail class.
		/// </summary>
		public TF_EventDetail(int eventHId, int toCityId, int preCityId, DateTime startDate, DateTime endDate, int dayNumber) {
			this.eventHId = eventHId;
			this.toCityId = toCityId;
			this.preCityId = preCityId;
			this.startDate = startDate;
			this.endDate = endDate;
			this.dayNumber = dayNumber;
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_EventDetail class.
		/// </summary>
		public TF_EventDetail(int id, int eventHId, int toCityId, int preCityId, DateTime startDate, DateTime endDate, int dayNumber) {
			this.id = id;
			this.eventHId = eventHId;
			this.toCityId = toCityId;
			this.preCityId = preCityId;
			this.startDate = startDate;
			this.endDate = endDate;
			this.dayNumber = dayNumber;
		}
		#endregion
		
		#region Properties
		/// <summary>
		/// Gets or sets the Id value.
		/// </summary>
		public int Id {
			get { return id; }
			set { id = value; }
		}
		
		/// <summary>
		/// Gets or sets the EventHId value.
		/// </summary>
		public int EventHId {
			get { return eventHId; }
			set { eventHId = value; }
		}
		
		/// <summary>
		/// Gets or sets the ToCityId value.
		/// </summary>
		public int ToCityId {
			get { return toCityId; }
			set { toCityId = value; }
		}
		
		/// <summary>
		/// Gets or sets the PreCityId value.
		/// </summary>
		public int PreCityId {
			get { return preCityId; }
			set { preCityId = value; }
		}
		
		/// <summary>
		/// Gets or sets the StartDate value.
		/// </summary>
		public DateTime StartDate {
			get { return startDate; }
			set { startDate = value; }
		}
		
		/// <summary>
		/// Gets or sets the EndDate value.
		/// </summary>
		public DateTime EndDate {
			get { return endDate; }
			set { endDate = value; }
		}
		
		/// <summary>
		/// Gets or sets the DayNumber value.
		/// </summary>
		public int DayNumber {
			get { return dayNumber; }
			set { dayNumber = value; }
		}
		#endregion
		
		#region Methods
		/// <summary>
		/// Saves a record to the TF_EventDetail table.
		/// </summary>
		public void Insert() {
			id = Convert.ToInt32(SqlClientUtility.ExecuteScalar("TF_EventDetailInsert", eventHId, toCityId, preCityId, startDate, endDate, dayNumber));
		}
		
		/// <summary>
		/// Updates a record in the TF_EventDetail table.
		/// </summary>
		public void Update() {
			SqlClientUtility.ExecuteNonQuery("TF_EventDetailUpdate", id, eventHId, toCityId, preCityId, startDate, endDate, dayNumber);
		}
		
		/// <summary>
		/// Deletes a record from the TF_EventDetail table by its primary key.
		/// </summary>
		public void Delete() {
			SqlClientUtility.ExecuteNonQuery("TF_EventDetailDelete", id);
		}
		
		/// <summary>
		/// Selects a single record from the TF_EventDetail table.
		/// </summary>
		public static TF_EventDetail Select(int id) {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_EventDetailSelect", id)) {
				if (dataReader.Read()) {
					return MakeTF_EventDetail(dataReader);
				} else {
					return null;
				}
			}
		}
		
		/// <summary>
		/// Selects all records from the TF_EventDetail table.
		/// </summary>
		public static List<TF_EventDetail> SelectAll() {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_EventDetailSelectAll")) {
				List<TF_EventDetail> tF_EventDetailList = new List<TF_EventDetail>();
				while (dataReader.Read()) {
					TF_EventDetail tF_EventDetail = MakeTF_EventDetail(dataReader);
					tF_EventDetailList.Add(tF_EventDetail);
				}
				return tF_EventDetailList;
			}
		}
		
		/// <summary>
		/// Creates a new instance of the TF_EventDetail class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static TF_EventDetail MakeTF_EventDetail(SqlDataReader dataReader) {
			TF_EventDetail tF_EventDetail = new TF_EventDetail();
			
			if (dataReader.IsDBNull(0) == false) {
				tF_EventDetail.Id = dataReader.GetInt32(0);
			}
			if (dataReader.IsDBNull(1) == false) {
				tF_EventDetail.EventHId = dataReader.GetInt32(1);
			}
			if (dataReader.IsDBNull(2) == false) {
				tF_EventDetail.ToCityId = dataReader.GetInt32(2);
			}
			if (dataReader.IsDBNull(3) == false) {
				tF_EventDetail.PreCityId = dataReader.GetInt32(3);
			}
			if (dataReader.IsDBNull(4) == false) {
				tF_EventDetail.StartDate = dataReader.GetDateTime(4);
			}
			if (dataReader.IsDBNull(5) == false) {
				tF_EventDetail.EndDate = dataReader.GetDateTime(5);
			}
			if (dataReader.IsDBNull(6) == false) {
				tF_EventDetail.DayNumber = dataReader.GetInt32(6);
			}

			return tF_EventDetail;
		}
		#endregion
	}
}
